package control;

import java.awt.Color;

import model.BoardModel;

public class PlayerAI extends Player {

	public PlayerAI(String n, Color c, BoardModel model) {
		super(n, c, model);
	}

	public Pos getNextMove() {

		if (getColor() == Kamisado.PlayerWhite) {

			int x = getModel().getMarkX();
			int y = getModel().getMarkY();

			// up
			int moveX = x - 1;
			int moveY = y;
			if (!getModel().isPosOutOfBoard(moveX, moveY)
					&& getModel().getField(moveX, moveY).getFigure() == null) {
				return new Pos(moveX, moveY);
			}

			// up left
			moveX = x - 1;
			moveY = y - 1;
			if (!getModel().isPosOutOfBoard(moveX, moveY)
					&& getModel().getField(moveX, moveY).getFigure() == null) {
				return new Pos(moveX, moveY);
			}

			// up right
			moveX = x - 1;
			moveY = y + 1;
			if (!getModel().isPosOutOfBoard(moveX, moveY)
					&& getModel().getField(moveX, moveY).getFigure() == null) {
				return new Pos(moveX, moveY);
			}

		}

		if (getColor() == Kamisado.PlayerBlack) {

			int x = getModel().getMarkX();
			int y = getModel().getMarkY();

			// up
			int moveX = x + 1;
			int moveY = y;
			if (!getModel().isPosOutOfBoard(moveX, moveY)
					&& getModel().getField(moveX, moveY).getFigure() == null) {
				return new Pos(moveX, moveY);
			}

			// up left
			moveX = x + 1;
			moveY = y - 1;
			if (!getModel().isPosOutOfBoard(moveX, moveY)
					&& getModel().getField(moveX, moveY).getFigure() == null) {
				return new Pos(moveX, moveY);
			}

			// up right
			moveX = x + 1;
			moveY = y + 1;
			if (!getModel().isPosOutOfBoard(moveX, moveY)
					&& getModel().getField(moveX, moveY).getFigure() == null) {
				return new Pos(moveX, moveY);
			}

		}

		return null;

	}

	@Override
	public boolean isAI() {
		return true;
	}

}
